<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>VUE Template</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气很{{info}}</h2>
        <h2>{{name}}出去玩</h2>
        <button @click="changeWeather">切换天气</button>
    </div>
</body>
    <script type="text/javascript">
        
        const vm = new Vue({
            el:'#root',
            data:{              
                name:'trentwu',
                isHot:true
                
            },
            methods:{
              changeWeather(){
                this.isHot=!this.isHot;
                this.name='xxm'
              }
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽'
                }
            },
            watch:{
                isHot:{
                    //isHot发生变化时调用
                    handler(newValue,oldValue){
                        console.log('isHot被修改',newValue,oldValue)
                    },
                    //初始化时handler立即调用
                    immediate:true
                },
                info:{
                    handler(newValue,o){
                        console.log('info被修改',newValue,o)
                    },
                    //immediate:true
                }
            }

        })

        vm.$watch('name',{
            handler(newValue,o){
                        console.log('name被修改',newValue,o)
            }
        })
    </script>
</html>